package com.zzt.questionbanktotalmaneger.controller;

import com.zzt.questionbanktotalmaneger.bean.dto.*;
import com.zzt.questionbanktotalmaneger.bean.dto.query.QuestionTypeQueryDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/questionType")
public class QuestionTypeController {
    @Autowired
    private RestTemplate template;

    @Value("${questionTypeManager.questionTypeServiceUrl}")
    private String questionTypeService;

    @RequestMapping("/addQuestionType")
    public Result addQuestionType(@RequestBody QuestionTypeModeListDTO questionTypeModeListDTO){
        Result result=template.postForObject(questionTypeService+"addQuestionType",questionTypeModeListDTO,Result.class);
        return result;
    }

    @RequestMapping("/deleteQuestionType")
    public Result deleteQuestion(long questionTypeId){
        Result result=template.postForObject(questionTypeService+"deleteQuestionType",questionTypeId,Result.class);
        return result;
    }

    @RequestMapping(value = "/getQuestionType")
    public Result<QuestionTypeModeListDTO> getQuestionType(long questionTypeId){
        Result<QuestionTypeModeListDTO> result=template.postForObject(questionTypeService+"getQuestionType",questionTypeId,Result.class);
        return result;
    }

    @RequestMapping("/getAPage")
    public PageResult<QuestionTypeDTO> getAPage(PageRequestMessage pageRequestMessage){
        PageResult<QuestionTypeDTO> pageResult=template.postForObject(questionTypeService+"getAPage",pageRequestMessage,PageResult.class);
        return pageResult;
    }

    @RequestMapping("/getASpecialPage")
    public PageResult<QuestionTypeDTO> getASpecialPage(QuestionTypeQueryDTO dto){
        PageResult<QuestionTypeDTO> pageResult=template.postForObject(questionTypeService+"getASpecialPage",dto,PageResult.class);
        return pageResult;
    }
}
